<% if Spree::Admin::RuntimeConfig.legacy_sidebar_navigation %>
  <%# Legacy navigation system %>
  <% if settings_area? %>
  <ul class="nav flex-column">
    <% if can?(:manage, current_store) %>
      <%= nav_item(Spree.t(:store_details), spree.edit_admin_store_path(section: 'general-settings'), icon: 'building-store', active: params[:section] == 'general-settings') %>
    <% end %>

    <% if can?(:manage, Spree.admin_user_class) %>
      <%= nav_item(Spree.t(:users), spree.admin_admin_users_path, icon: 'users', active: %w[admin_users invitations roles].include?(controller_name)) %>
    <% end %>

    <%= nav_item(Spree.t(:emails), spree.edit_admin_store_path(section: 'emails'), icon: 'send', active: params[:section] == 'emails') if can?(:manage, current_store) %>
    <%= nav_item(Spree.t(:policies), spree.admin_policies_path, icon: 'list-check') if can?(:manage, Spree::Policy) %>
    <%= nav_item(Spree.t(:checkout), spree.edit_admin_store_path(section: 'checkout'), icon: 'shopping-cart', active: params[:section] == 'checkout') if can?(:manage, current_store) %>
    <%= render_admin_partials(:store_settings_nav_partials) %>

    <% if can?(:manage, Spree::CustomDomain) %>
      <%= nav_item(Spree.t(:domains), spree.admin_custom_domains_path, icon: 'world-www') %>
    <% end %>

    <% if can?(:manage, Spree::PaymentMethod) %>
      <%= nav_item(Spree.t(:payments), spree.admin_payment_methods_path, icon: 'credit-card') %>
    <% end %>

    <% if can?(:manage, Spree::Zone) %>
      <%= nav_item(Spree.t(:zones), spree.admin_zones_path, icon: 'world', active: %w[zones countries states].include?(controller_name)) %>
    <% end %>

    <% if can?(:manage, Spree::ShippingMethod) %>
      <%= nav_item(Spree.t(:shipping), spree.admin_shipping_methods_path, icon: 'truck', active: %w[shipping_methods shipping_categories].include?(controller_name)) %>
    <% end %>

    <% if can?(:manage, Spree::TaxRate) %>
      <%= nav_item(Spree.t(:tax), spree.admin_tax_rates_path, icon: 'receipt-tax', active: %w[tax_rates tax_categories stripe_tax_registrations].include?(controller_name)) %>
    <% end %>

    <% if can?(:manage, Spree::ReturnAuthorizationReason) %>
      <%= nav_item(Spree.t(:returns), spree.admin_return_authorization_reasons_path, icon: 'receipt-refund', active: %w[refund_reasons reimbursement_types return_authorization_reasons].include?(controller_name)) %>
    <% end %>

    <% if can?(:manage, Spree::StockLocation) %>
      <%= nav_item(Spree.t(:stock_locations), spree.admin_stock_locations_path, icon: 'map-pin') %>
    <% end %>

    <% if can?(:manage, Spree::MetafieldDefinition) %>
      <%= nav_item(Spree.t(:metafield_definitions), spree.admin_metafield_definitions_path, icon: 'list-details') %>
    <% end %>

    <% if can?(:manage, Spree::Store) %>
      <% if spree.respond_to?(:admin_audits_path) %>
        <%= nav_item(Spree.t('admin.audit_log'), spree.admin_audits_path, icon: 'history', active: %w[audits exports imports].include?(controller_name)) %>
      <% else %>
        <li class="nav-item">
          <%= external_link_to nil, 'https://spreecommerce.org/pricing', class: 'nav-link d-flex align-items-center w-100' do %>
            <%= icon 'history' %>
            <%= Spree.t('admin.audit_log') %>

            <span class="badge ml-auto rounded-pill" data-controller="tooltip">
              Enterprise
              <%= tooltip("This feature is part of the Enterprise Edition.") %>
            </span>
          <% end %>
        </li>
      <% end %>
    <% end %>

    <% if can?(:manage, Spree::OauthApplication) %>
      <%= nav_item(Spree.t(:developers), spree.admin_oauth_applications_path, icon: 'terminal', active: %w[oauth_applications webhooks_subscribers].include?(controller_name)) %>
    <% end %>

    <%= nav_item(Spree.t('admin.edit_profile'), spree.edit_admin_profile_path, icon: 'user-scan') %>

    <%= render_admin_partials(:settings_nav_partials) %>
  </ul>
<% else %>
  <ul class="nav flex-column">
    <% if can?(:manage, current_store) %>
      <% unless current_store.setup_completed? %>
        <%= nav_item(nil, spree.admin_getting_started_path, icon: 'map') do %>
          <%= icon 'map' %>
          <%= Spree.t('admin.getting_started') %>
          <span class="badge ml-auto badge-info">
            <%= current_store.setup_tasks_done %><span class="opacity-50">/<%= current_store.setup_tasks_total %></span>
          </span>
        <% end %>
      <% end %>
    <% end %>

    <%= nav_item(Spree.t(:home), spree.admin_path, icon: 'home', active: controller_name == 'dashboard' && action_name == 'show') %>

    <%= render 'spree/admin/shared/sidebar/orders_nav' %>
    <%= render 'spree/admin/shared/sidebar/returns_nav' %>
    <%= render 'spree/admin/shared/sidebar/products_nav' %>
    <%= render 'spree/admin/shared/sidebar/vendors_nav' %>
    <%= render 'spree/admin/shared/sidebar/customers_nav' %>
    <%= render 'spree/admin/shared/sidebar/promotions_nav' %>

    <% if can?(:manage, Spree::Report) %>
      <%= nav_item(Spree.t(:reports), spree.admin_reports_path, icon: 'chart-bar') %>
    <% end %>

    <%= render_admin_partials(:store_nav_partials) %>

    <%= render 'spree/admin/shared/sidebar/storefront_nav' %>
    <%= render 'spree/admin/shared/sidebar/integrations_nav' %>
  </ul>

  <div class="mt-auto d-flex flex-column">
    <%= render 'spree/admin/shared/sidebar/enterprise_edition_notice' %>

    <ul class="nav flex-column mb-2">
      <% if can?(:manage, current_store) %>
        <%= nav_item(Spree.t(:settings), spree.edit_admin_store_path(section: 'general-settings'), icon: 'settings', active: params[:section] == 'general-settings') %>
        <%= nav_item(Spree.t(:users), spree.admin_admin_users_path, icon: 'users') %>
      <% end %>
    </ul>
  </div>
  <% end %>
<% else %>
  <%# New navigation system %>
  <% if settings_area? %>
    <%= render_navigation(:settings) %>
  <% else %>
    <%= render_navigation(:sidebar) %>

    <div class="mt-auto d-flex flex-column">
      <%= render 'spree/admin/shared/sidebar/enterprise_edition_notice' %>
    </div>
  <% end %>
<% end %>
